package com.op.studyingliteapp.fragment.viewer;

import android.app.Fragment;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;
import com.op.studyingliteapp.R;
import com.op.studyingliteapp.sender.*;
import com.op.studyingliteapp.sender.Runtime;
import com.op.studyingliteapp.sender.ui.view.BrushesView;
import com.op.studyingliteapp.sender.ui.view.PdfViewPager;
import com.op.util.DensityUtils;
import com.op.util.ScreenSendUtils;


/**
 * Created by Genji on 2015/7/5.
 */
public class ViewPagerFragment extends Fragment {
    private PdfViewPager pdfViewPager;
    private View root, penSetting;
    private BrushesView brushesView;
    private String TAG = this.getClass().getSimpleName();

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        this.root = inflater.inflate(R.layout.fragment_viewpager, null);
        this.penSetting = inflater.inflate(R.layout.set_pen, null);
        return this.root;
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        String url = getArguments().getString("url");

        pdfViewPager = (PdfViewPager) view.findViewById(R.id.viewPager);
        Button button = (Button) view.findViewById(R.id.pen);

        brushesView = new BrushesView(this.penSetting, DensityUtils.dip2px(getActivity(), 400), DensityUtils.dip2px(getActivity(), 50), button);

        PDFAdapter pdfAdapter = new PDFAdapter(getActivity(), url);
        pdfViewPager.setAdapter(pdfAdapter);
        pdfViewPager.setCurrentItem(0);
        pdfViewPager.setSelected(true);
        brushesView.associate(pdfViewPager);
        pdfAdapter.setPdfViewPager(pdfViewPager);
        Runtime.setView(pdfViewPager);


    }

    @Override
    public void onResume() {
        super.onResume();

    }

    @Override
    public void onDestroy() {
        brushesView.dismiss();
        System.gc();
        Log.i(TAG, "onDestroy");

        super.onDestroy();
    }
}
